/**
 * <p>文件名:		SpringBeanOperatorImpl.java</p>
 * <p>版权:		CopyrightTag</p>
 * <p>公司:		CompanyTag</p>
 * @author		周华彬(zhouhuabin@ctfo.com, zhou_hua_bin@163.com)
 */

package com.caits.lbs.framework.services.jmx;

import java.lang.reflect.Method;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;

import com.caits.lbs.framework.log.CommonLogFactory;
import com.caits.lbs.framework.utils.ObjectUtils;
import com.caits.lbs.framework.utils.SpringUtils;
import com.caits.lbs.framework.utils.StringUtils;

/**
 * <p>
 * SpringBeanOperatorImpl
 * </p>
 * <p>
 * spring实例bean的jmx操作实现类
 * </p>
 *
 * @author 周华彬(zhouhuabin@ctfo.com, zhou_hua_bin@163.com)
 * @version 0.0.0
 *          <table style="border:1px solid gray;">
 *          <tr>
 *          <th width="100px">版本号</th>
 *          <th width="100px">动作</th>
 *          <th width="100px">修改人</th>
 *          <th width="100px">修改时间</th>
 *          </tr>
 *          <!-- 以 Table 方式书写修改历史 -->
 *          <tr>
 *          <td>0.0.0</td>
 *          <td>创建类</td>
 *          <td>zhouhuabin</td>
 *          <td>2015年1月4日 下午3:59:32</td>
 *          </tr>
 *          <tr>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          </tr>
 *          </table>
 */
public class SpringBeanOperatorImpl implements ISpringBeanOperator {

	/** TODO */
	protected Logger log = CommonLogFactory.getLog();
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.caits.lbs.framework.services.jmx.ISpringBeanOperator#
	 * operateSprintBeanMethod(java.lang.String, java.lang.String)
	 */
	@Override
	public String operateSprintBeanMethod(String beanName, String methodName) {
		ApplicationContext ac = SpringUtils.getApplicationContext();
		if (ac != null) {
			try {
				Object bean = ac.getBean(beanName);
				Method method = org.springframework.util.ClassUtils.getMethod(bean.getClass(), methodName);
				Object value = method.invoke(bean);
				return (value==null)?"":value.toString();
			} catch (Exception e) {
				log.error("获取指定beanName="+beanName+"的"+methodName+"方法异常,msg="+e.getLocalizedMessage(),e);
			}
		}
		return null;
	}

}
